package com.ruoyi.web.controller.ems;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.HUAWEI.EmsCustomerSn;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IEmsCustomerSnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户条码回传Controller
 *
 * @author ruoyi
 * @date 2023-07-14
 */
@Api(tags = "客户条码回传api")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/sn" )
public class EmsCustomerSnController extends BaseController {

    private final IEmsCustomerSnService iEmsCustomerSnService;

    /**
     * 查询客户条码回传列表
     */
    @ApiOperation(value = "客户条码回传列表",response = EmsCustomerSn.class)
    @PreAuthorize("@ss.hasPermi('system:sn:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmsCustomerSn emsCustomerSn)
    {
        startPage();
        LambdaQueryWrapper<EmsCustomerSn> lqw = new LambdaQueryWrapper<EmsCustomerSn>();
        if (StringUtils.isNotBlank(emsCustomerSn.getCustomLinkId())){
            lqw.eq(EmsCustomerSn::getCustomLinkId ,emsCustomerSn.getCustomLinkId());
        }
        if (StringUtils.isNotBlank(emsCustomerSn.getPartNo())){
            lqw.eq(EmsCustomerSn::getPartNo ,emsCustomerSn.getPartNo());
        }
        if (StringUtils.isNotBlank(emsCustomerSn.getTaskNo())){
            lqw.eq(EmsCustomerSn::getTaskNo ,emsCustomerSn.getTaskNo());
        }
        if (StringUtils.isNotBlank(emsCustomerSn.getSnType())){
            lqw.eq(EmsCustomerSn::getSnType ,emsCustomerSn.getSnType());
        }
        if (StringUtils.isNotBlank(emsCustomerSn.getLinkType())){
            lqw.eq(EmsCustomerSn::getLinkType ,emsCustomerSn.getLinkType());
        }
        if (StringUtils.isNotBlank(emsCustomerSn.getSn())){
            lqw.eq(EmsCustomerSn::getSn ,emsCustomerSn.getSn());
        }
        if (StringUtils.isNotBlank(emsCustomerSn.getLinkedCustomValue())){
            lqw.eq(EmsCustomerSn::getLinkedCustomValue ,emsCustomerSn.getLinkedCustomValue());
        }
        if (StringUtils.isNotBlank(emsCustomerSn.getLinkedCustomKeyname())){
            lqw.like(EmsCustomerSn::getLinkedCustomKeyname ,emsCustomerSn.getLinkedCustomKeyname());
        }
        if (StringUtils.isNotBlank(emsCustomerSn.getSiteId())){
            lqw.eq(EmsCustomerSn::getSiteId ,emsCustomerSn.getSiteId());
        }
        if (StringUtils.isNotBlank(emsCustomerSn.getCreationDate())){
            lqw.eq(EmsCustomerSn::getCreationDate ,emsCustomerSn.getCreationDate());
        }
        if (StringUtils.isNotBlank(emsCustomerSn.getCreatedBy())){
            lqw.eq(EmsCustomerSn::getCreatedBy ,emsCustomerSn.getCreatedBy());
        }
        if (StringUtils.isNotBlank(emsCustomerSn.getCreatedByName())){
            lqw.like(EmsCustomerSn::getCreatedByName ,emsCustomerSn.getCreatedByName());
        }
        if (StringUtils.isNotBlank(emsCustomerSn.getRes())){
            lqw.eq(EmsCustomerSn::getRes ,emsCustomerSn.getRes());
        }
        List<EmsCustomerSn> list = iEmsCustomerSnService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出客户条码回传列表
     */
    @PreAuthorize("@ss.hasPermi('system:sn:export')" )
    @Log(title = "客户条码回传" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(EmsCustomerSn emsCustomerSn) {
        LambdaQueryWrapper<EmsCustomerSn> lqw = new LambdaQueryWrapper<EmsCustomerSn>(emsCustomerSn);
        List<EmsCustomerSn> list = iEmsCustomerSnService.list(lqw);
        ExcelUtil<EmsCustomerSn> util = new ExcelUtil<EmsCustomerSn>(EmsCustomerSn. class);
        return util.exportExcel(list, "sn" );
    }

    /**
     * 获取客户条码回传详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sn:query')" )
    @GetMapping(value = "/{customLinkId}" )
    public AjaxResult getInfo(@PathVariable("customLinkId" ) String customLinkId) {
        return AjaxResult.success(iEmsCustomerSnService.getById(customLinkId));
    }

    /**
     * 新增客户条码回传
     */
    @PreAuthorize("@ss.hasPermi('system:sn:add')" )
    @Log(title = "客户条码回传" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsCustomerSn emsCustomerSn) {
        return toAjax(iEmsCustomerSnService.save(emsCustomerSn) ? 1 : 0);
    }

    /**
     * 修改客户条码回传
     */
    @PreAuthorize("@ss.hasPermi('system:sn:edit')" )
    @Log(title = "客户条码回传" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsCustomerSn emsCustomerSn) {
        return toAjax(iEmsCustomerSnService.updateById(emsCustomerSn) ? 1 : 0);
    }

    /**
     * 删除客户条码回传
     */
    @PreAuthorize("@ss.hasPermi('system:sn:remove')" )
    @Log(title = "客户条码回传" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{customLinkIds}" )
    public AjaxResult remove(@PathVariable String[] customLinkIds) {
        return toAjax(iEmsCustomerSnService.removeByIds(Arrays.asList(customLinkIds)) ? 1 : 0);
    }
}
